package com.ruoyi.daily.service.impl;

import com.github.pagehelper.PageHelper;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.daily.domain.dto.*;
import com.ruoyi.daily.domain.vo.ByDateAndPageVo;
import com.ruoyi.daily.domain.vo.ByDateVo;
import com.ruoyi.daily.mapper.CustomerServiceMapper;
import com.ruoyi.daily.service.CustomerServiceService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author cmz
 * @Date 2024-05-30 15:15
 */
@Service
public class CustomerServiceServiceImpl implements CustomerServiceService {
    @Resource
    private CustomerServiceMapper customerServiceMapper;
    @Override
    public R<FalseReceiptDto> falseReceipt() {
        FalseReceiptDto falseReceiptVo = customerServiceMapper.falseReceipt();
        return R.ok(falseReceiptVo);
    }

    @Override
    public R<WorkOrderSolveDto> workOrderSolve() {
        WorkOrderSolveDto workOrderSolveDto = customerServiceMapper.workOrderSolve();
        return R.ok(workOrderSolveDto);
    }

    @Override
    public R<List<EchartsDto>> myComplaintEcharts(ByDateVo byDateVo) {
        List<EchartsDto> myComplaint = customerServiceMapper.myComplaintEcharts(byDateVo);
        return R.ok(myComplaint);
    }

    @Override
    public R<List<MyComplaintListDto>> myComplaintList(ByDateAndPageVo byDateAndPageVo) {
        //PageHelper.startPage(byDateAndPageVo.getPageDate());
        List<MyComplaintListDto>  myComplaint = customerServiceMapper.myComplaintList(byDateAndPageVo);
        return R.ok(myComplaint);
    }

    @Override
    public R<List<EchartsDto>> complaintMyEcharts(ByDateVo byDateVo) {
        List<EchartsDto> myComplaint = customerServiceMapper.complaintMyEcharts(byDateVo);
        return R.ok(myComplaint);
    }

    @Override
    public R<List<MyComplaintListDto>> complaintMyList(ByDateAndPageVo byDateAndPageVo) {
        //PageHelper.startPage(byDateAndPageVo.getPageDate());
        List<MyComplaintListDto>  myComplaint = customerServiceMapper.complaintMyList(byDateAndPageVo);
        return R.ok(myComplaint);
    }

    @Override
    public R<EchartsCountDto> customerComplaint(ByDateVo byDateVo) {
        EchartsCountDto dto = new EchartsCountDto();
        List<EchartsDto>  echartsVo = customerServiceMapper.customerComplaint(byDateVo);
        Integer count = 0;
        for (EchartsDto echartsDto : echartsVo) {
            count = count+echartsDto.getValue();
        }
        dto.setTitle("工单量");
        dto.setCount(count);
        dto.setList(echartsVo);
        return R.ok(dto);
    }

    @Override
    public R<EchartsCountDto> inboundComplaintEcharts(ByDateVo byDateVo) {
        EchartsCountDto dto = new EchartsCountDto();
        List<EchartsDto>  echartsVo = customerServiceMapper.inboundComplaintEcharts(byDateVo);
        Integer count = 0;
        for (EchartsDto echartsDto : echartsVo) {
            count = count+echartsDto.getValue();
        }
        DecimalFormat df = new DecimalFormat("#.0");
        for (EchartsDto echartsDto : echartsVo) {
            echartsDto.setName(echartsDto.getName()+"\n"+df.format((echartsDto.getValue()*1.0/count)*100)+"%");
        }
        dto.setCount(count);
        dto.setTitle("投诉单量");
        dto.setList(echartsVo);
        return R.ok(dto);
    }

    @Override
    public R<List<InboundComplaintDto>> inboundComplaintList(ByDateAndPageVo byDateAndPageVo) {
        PageHelper.startPage(byDateAndPageVo.getPageDate());
        List<InboundComplaintDto> list = customerServiceMapper.inboundComplaintList(byDateAndPageVo);
        return R.ok(list);
    }

    @Override
    public R<WorkOrderResolutionRateDto> workOrderResolutionRate() {
        WorkOrderResolutionRateDto workOrderResolutionRateDto = new WorkOrderResolutionRateDto();
        workOrderResolutionRateDto.setFirstFollowUpTimeoutRate("76.5");
        workOrderResolutionRateDto.setProcessingTimeoutRate("76.5");
        workOrderResolutionRateDto.setWorkOrderCompletionRate("76.5");
        workOrderResolutionRateDto.setOneTimeResolutionRate("76.5");
        workOrderResolutionRateDto.setShouldFollowTheQuantityFirst(0);
        workOrderResolutionRateDto.setHandlingCapacity(0);
        workOrderResolutionRateDto.setAverageProcessingTime("15小时24分钟");
        workOrderResolutionRateDto.setAverageFirstHeelDuration("15小时24分钟");
        return R.ok(workOrderResolutionRateDto);
    }

    @Override
    public R<List<EchartsDto>> falseReceiptEcharts() {
        List<EchartsDto> list = customerServiceMapper.falseReceiptEcharts();
        return R.ok(list);
    }
}
